package com.sunnybear.framework.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;

import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.sunnybear.framework.R;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import io.reactivex.annotations.NonNull;

/**
 * <p>
 *  2018/4/23.
 */
public abstract class BaseBottomSheetDialog<VBD extends ViewDataBinding> extends BottomSheetDialog {

    protected Context mContext;
    protected VBD mViewDataBinding;

    public BaseBottomSheetDialog(@NonNull Context context) {
        super(context);
        initView(context);
    }

    public BaseBottomSheetDialog(@NonNull Context context, int theme) {
        super(context, theme);
        initView(context);
    }

    protected BaseBottomSheetDialog(@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView(context);
    }

    /**
     * 设置布局id
     *
     * @return 布局id
     */
    public abstract int getLayoutId();

    /**
     * 绑定数据
     */
    public abstract void bindingData();

    private void initView(Context context) {
        mContext = context;
        mViewDataBinding = DataBindingUtil.inflate(LayoutInflater.from(context), getLayoutId(), null, false);
        setContentView(mViewDataBinding.getRoot());
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bindingData();
    }

    /**
     * 设置BottomSheetDialog的背景色
     *
     * @param resId
     */
    protected void setBackground(int resId) {
        getWindow().findViewById(R.id.design_bottom_sheet)
                .setBackgroundResource(resId);
    }
}
